Skip to content

reusable xml id validation method#4584

Merged
Jimmy-Joseph19 merged 17 commits intomainfrom
shared-xml-id-validation
Apr 27, 2026
Merged

reusable xml id validation method#4584
Jimmy-Joseph19 merged 17 commits intomainfrom
shared-xml-id-validation

Conversation

@Jimmy-Joseph19
Copy link
Copy Markdown
Contributor

Add validateId method to project-access for reusability across multiple packages

@Jimmy-Joseph19 Jimmy-Joseph19 requested review from a team as code owners April 22, 2026 06:59
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

🦋 Changeset detected

Latest commit: 4e30d6e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 52 packages
Name Type
@sap-ux/project-access Minor
@sap-ux/fe-fpm-writer Patch
@sap-ux/abap-deploy-config-sub-generator Patch
@sap-ux/abap-deploy-config-writer Patch
@sap-ux/adp-flp-config-sub-generator Patch
@sap-ux/adp-tooling Patch
@sap-ux/annotation-generator Patch
@sap-ux/app-config-writer Patch
@sap-ux/cap-config-writer Patch
@sap-ux/cf-deploy-config-sub-generator Patch
@sap-ux/cf-deploy-config-writer Patch
@sap-ux/create Patch
@sap-ux/deploy-config-sub-generator Patch
@sap-ux/environment-check Patch
@sap-ux/eslint-plugin-fiori-tools Patch
@sap-ux/fiori-annotation-api Patch
@sap-ux/fiori-app-sub-generator Patch
@sap-ux/fiori-elements-writer Patch
@sap-ux/fiori-generator-shared Patch
@sap-ux/flp-config-inquirer Patch
@sap-ux/flp-config-sub-generator Patch
@sap-ux/generator-adp Patch
@sap-ux/inquirer-common Patch
@sap-ux/launch-config Patch
@sap-ux/mockserver-config-writer Patch
@sap-ux/odata-service-inquirer Patch
@sap-ux/odata-service-writer Patch
@sap-ux/preview-middleware Patch
@sap-ux/project-input-validator Patch
@sap-ux/project-integrity Patch
@sap-ux/repo-app-import-sub-generator Patch
@sap-ux/telemetry Patch
@sap-ux/ui5-application-inquirer Patch
@sap-ux/ui5-library-reference-inquirer Patch
@sap-ux/ui5-library-reference-sub-generator Patch
@sap-ux/ui5-library-reference-writer Patch
@sap-ux/ui5-library-writer Patch
@sap-ux/ui5-test-writer Patch
@sap-ux-private/adaptation-editor-tests Patch
@sap-ux/fe-fpm-cli Patch
@sap-ux/backend-proxy-middleware-cf Patch
@sap-ux/fiori-freestyle-writer Patch
@sap-ux-private/preview-middleware-client Patch
@sap-ux/abap-deploy-config-inquirer Patch
@sap-ux/deploy-config-generator-shared Patch
@sap-ux/ui-service-sub-generator Patch
@sap-ux/ui5-library-sub-generator Patch
@sap-ux/cf-deploy-config-inquirer Patch
@sap-ux/deploy-tooling Patch
@sap-ux/ui-service-inquirer Patch
@sap-ux/ui5-library-inquirer Patch
@sap-ux/generator-simple-fe Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@hyperspace-insights
Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Add Reusable validateId Method to project-access

New Feature

✨ Introduces a reusable validateId function in @sap-ux/project-access that checks whether an XML element ID is unique across view and fragment files. This consolidates duplicate ID-checking logic previously scattered across packages.

The new function supports two overloads:

  • Synchronous: when XML file contents are provided directly as strings
  • Asynchronous: when an appPath is provided to scan the filesystem for .view.xml and .fragment.xml files (with optional mem-fs-editor support)

Changes

  • packages/project-access/src/library/helpers.ts: Added the validateId function with synchronous and asynchronous overloads. Uses fast-xml-parser for XML parsing and recursively searches for element IDs. Also added findFilesByExtension and mem-fs-editor imports.
  • packages/project-access/src/library/index.ts: Exported validateId from the library index.
  • packages/fe-fpm-writer/src/common/file.ts: Replaced the local checkElementIdAvailable implementation (which used @xmldom/xmldom's DOMParser) with a call to the new shared validateId from @sap-ux/project-access, removing the DOMParser dependency.
  • packages/project-access/test/library/helpers.test.ts: Added a comprehensive validateId test suite covering ID existence checks in views and fragments, nested elements, empty files, invalid XML, special character IDs, and the validatedIds exclusion list.

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.20.23

  • Summary Prompt: Default Prompt
  • Output Template: Default Template
  • LLM: anthropic--claude-4.6-sonnet
  • File Content Strategy: Full file content
  • Correlation ID: 7f6ca6b8-428f-40f7-98e5-7d6cd51dc3ef
  • Event Trigger: pull_request.opened

Copy link
Copy Markdown
Contributor

@hyperspace-insights hyperspace-insights Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces a useful validateId abstraction in @sap-ux/project-access, but has a critical correctness bug in the async path: findFilesByExtension returns file paths, not file contents, so the XML parser receives path strings instead of XML and ID collision detection never fires when appPath is used. There are also secondary issues: a dead-code assignment in the async IIFE (fileContents is always undefined there), and the synchronous-overload tests are all async/await which silently masks whether the synchronous contract is actually being exercised.

PR Bot Information

Version: 1.20.23

  • LLM: anthropic--claude-4.6-sonnet
  • File Content Strategy: Full file content
  • Agent Instructions:
  • Correlation ID: 7f6ca6b8-428f-40f7-98e5-7d6cd51dc3ef
  • Event Trigger: pull_request.opened

Comment thread packages/project-access/src/library/helpers.ts Outdated
Comment thread packages/project-access/src/library/helpers.ts Outdated
Comment thread packages/fe-fpm-writer/src/common/file.ts Outdated
Comment thread packages/project-access/test/library/helpers.test.ts Outdated
815are
815are previously approved these changes Apr 22, 2026
Copy link
Copy Markdown
Contributor

@815are 815are left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked code:

  1. code changes are easy to understand and approach to use fast-xml-parser instead of xmldom/xmldom
  2. changelog persists
  3. I did not test manually

Copy link
Copy Markdown
Contributor

@Klaus-Keller Klaus-Keller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding AI verdict:

Summary

                                                                                                                                                            Extracts a validateId function into @sap-ux/project-access to consolidate XML element ID uniqueness checking that was previously inline in @sap-ux/fe-fpm-writer.   

The function supports sync (files provided directly) and async (filesystem scan via appPath) overloads, and switches from @xmldom/xmldom DOMParser to
fast-xml-parser.


Issues Found

  1. Critical: Async path reads file paths, not file contents (helpers.ts:481-484)

The async branch calls findFilesByExtension which returns file paths, then passes them to fsEditor.read(path) — this part is actually correct since
mem-fs-editor.read() takes a path and returns the file content. So the bot reviewer's concern about this appears to be a false positive. However, there's still a
problem: the async path is completely untested. The test suite only covers the sync overload and a trivial "no options" case. There are no tests exercising appPath
with mocked filesystem reads.

  1. Behavioral change: XML parser switch (helpers.ts:378-386)

The original code used @xmldom/xmldom DOMParser with getElementById(). The new code uses fast-xml-parser with a custom recursive hasElementWithId() that searches
for @_id attributes. This is a subtle behavioral difference:

  • getElementById searches for XML id attributes specifically (per DOM spec).
  • The new code searches for any attribute literally named id at @_id. This should be equivalent for SAPUI5 XML views, but edge cases around namespaced id attributes
    (e.g., xml:id) or custom id attribute handling could differ.
  1. Deep import from internal path (file.ts:4)

import { findFilesByExtension } from '@sap-ux/project-access/dist/file';

This pre-existing deep import into /dist/file is not addressed by this PR. The PR already adds findFilesByExtension as an import in helpers.ts — it would be cleaner
to also re-export it from the package's public API and update the consumer, rather than keeping the fragile /dist/ path import.

  1. Overload complexity (helpers.ts:313-361)

Three overload signatures for what is essentially two modes (sync with files, async with appPath/nothing). The third overload (options?: undefined →
Promise) that always returns true has questionable utility — a caller with no files and no appPath always gets true, which is a no-op validation. Consider
whether this overload is actually needed or if callers should just skip calling validateId when they have nothing to validate against.

  1. Nested function definitions inside implementation (helpers.ts:370-470)

Five helper functions (checkElementIdAvailable, checkIdInValue, hasElementWithId, validateAgainstFiles, and the async IIFE) are all defined inside the validateId
function body. This means they are re-created on every call. For a function called in a tight loop (the generateUniqueElementId loop calls it up to 1000 times),
this is wasteful. Extract the pure helpers (hasElementWithId, checkIdInValue, checkElementIdAvailable) to module scope.

  1. Missing test coverage for async/appPath overload

The test suite only tests:

  • Sync overload with files provided
  • Trivial async case with no options (always returns true)

There are no tests for the appPath overload, which is the more complex and error-prone path involving filesystem reads, file filtering, and mem-fs-editor
integration. This is the path most likely to have bugs.

  1. validatedIds check placement (helpers.ts:467)

function validateAgainstFiles(files: string[]): boolean {
return (
files.every((content) => content === '' || checkElementIdAvailable(baseId, content)) &&
!validatedIds?.includes(baseId)
);
}

The validatedIds check should come first — it's O(n) at worst but avoids parsing XML entirely if the id is already in the list. Minor optimization but worth noting
for the 1000-iteration loop in the caller.


Verdict

The core idea is sound — centralizing ID validation is a good refactor. However, the PR needs work before merging:

  1. Add tests for the appPath async overload
  2. Extract inner helper functions to module scope (performance in hot loop)
  3. Reorder validatedIds check before XML parsing
  4. Consider simplifying the overload signatures

Comment thread .changeset/funny-socks-rescue.md Outdated
Comment thread packages/project-access/src/library/index.ts Outdated
heimwege
heimwege previously approved these changes Apr 24, 2026
Copy link
Copy Markdown
Contributor

@heimwege heimwege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deep import mentioned by @Klaus-Keller still exists. But it was pre-existing, so not a blocker

  • changeset ok
  • did NOT test manually
  • coverage is good

Comment thread packages/fe-fpm-writer/src/common/file.ts Outdated
815are
815are previously approved these changes Apr 24, 2026
Copy link
Copy Markdown
Contributor

@815are 815are left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reapproving

heimwege
heimwege previously approved these changes Apr 24, 2026
Copy link
Copy Markdown
Contributor

@heimwege heimwege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-approve

Copy link
Copy Markdown
Contributor

@Klaus-Keller Klaus-Keller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Jimmy-Joseph19,
all my comments have been addressed.
Approved from my side.

Copy link
Copy Markdown
Contributor

@815are 815are left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reapproving

@sonarqubecloud
Copy link
Copy Markdown

@Jimmy-Joseph19 Jimmy-Joseph19 merged commit 1d60871 into main Apr 27, 2026
18 checks passed
@Jimmy-Joseph19 Jimmy-Joseph19 deleted the shared-xml-id-validation branch April 27, 2026 19:33
eouin added a commit that referenced this pull request Apr 28, 2026
…x-issues-after-comments

* 'main' of github.com:SAP/open-ux-tools:
  chore: apply latest changesets
  feat: add Claude Code plugin support (#4575)
  chore: apply latest changesets
  reusable xml id validation method (#4584)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants